##!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : ${DATE} ${TIME}
# @Author  : Mat
# @File    : ${NAME}.py
# @Software: ${PRODUCT_NAME}
# -- read file ---
file= open("data", 'r')
dcp_str= file.read()
print("密文: "+ dcp_str)
dcp_l= list(dcp_str)
# --- initialize frequency dict ---
f={}
for i in range(26):
    f[chr(i+ord('A'))]= 0
# --- write frequency ---
for c in dcp_l:
    if c==' ':
        continue
    f[c]+=1
# --- sort ---
sorted_f= sorted(f.items(), key= lambda x:x[1], reverse=True)
# --- decrypt ---
key_d={}
for i in range(26):
    if(c==' '):
        print(c, end="")
    else:
        key_d[chr(i + ord('A'))] = chr(i + ord('A'))
# --- guessing ---
# ---
key_d['P']='e'
key_d['Z']='t'
key_d['W']='h'
# --- thSt
key_d['S']='a'
# --- QaO
key_d['O']='s'
key_d['Q']='w'
# --- wUth
key_d['U']='i'
# --- haFe
key_d['F']='v'
# --- seveEaX
key_d['E']='r'
key_d['X']='l'
# ---VisHlMseV
key_d['V']='d'
# --- direHt
key_d['H']='c'
# --- MB
key_d['M']='o'
# --- Yolitical
key_d['Y']='p'
# --- AeeD
key_d['A']='b'
# --- represeDtatives
key_d['D']='n'
# --- Tade
key_d['T']='m'
# --- inBormal
key_d['B']='f'
# --- conJ
key_d['J']='g'
# --- bIt
key_d['I']='u'
# --- GesterdaG
key_d['G']='y'


# --- output result ---
print("解密中：")
for c in dcp_l:
    if (c == ' '):
        print(c, end="")
    else:
        print(key_d[c], end="")


